<?php
class signController extends  appController{
	
	public function index()
	{
		$page = yf_empty(intval($_GET['page']), 1, true);
		
	
		$list = Model('sign')->get_list($sort, $page);
		$this->assign('ad_list', $list['data']);
		$this->assign('count', $list['count']);
		$this->assign('user_list_page', $list['pagelink']);
		// 		var_dump($list['data']);
		$this->display("index.html");
	}
	
	public function persent(){
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
		$persent_list=Model('sign')->persent_list($page);
		$this->assign('persent_list',$persent_list['data']);
		$this->assign('user_list_page',$persent_list['pagelink']);
		$this->assign('count',$persent_list['count']);
		$this->display('persent_list.html');
	}
	
	public function addPersent(){
		$this->assign('action','createPersent');
		$this->display('persent_edit.html');
	}
	public function editPersent(){
		$id=isset($_REQUEST['id'])?intval($_REQUEST['id']):0;
		$persent = Model('sign')->get_persent($id);
		$this->assign('persent',$persent);
		$this->assign('id',$id);
		$this->assign('action','updatePersent');
		$this->display('persent_edit.html');
	}
	
	public function createPersent(){
		$info['name']=isset($_POST['name'])?$_POST['name']:'';
		$info['url']=isset($_POST['url'])?$_POST['url']:'';
		$info['thumb']=isset($_POST['thumb'])?$_POST['thumb']:'';
		$info['number']=isset($_POST['number'])?intval($_POST['number']):0;
		$info['addtime'] = $_SERVER['REQUEST_TIME'];
		$data=array('error'=>1,'content'=>'');
		if($_POST['name']=='')
		{
			$data['error']=1;
			$data['content']=Lang('礼品名不能为空');
			$this->showMsg($data);
		}
		$result=Model('sign')->insert($info,'sign_persent');
		if($result)
		{
			$data['error']=0;
			$data['content']=Lang('SUCCESS_EDIT');
		
		}
		else
		{
			$data['content']=Lang('INVALID_OPERATION');
		}
		$this->showMsg($data);
	}
	public function updatePersent(){
		$id=isset($_POST['id'])?$_POST['id']:'';
		$info['name']=isset($_POST['name'])?$_POST['name']:'';
		$info['url']=isset($_POST['url'])?$_POST['url']:'';
		$info['thumb']=isset($_POST['thumb'])?$_POST['thumb']:'';
		$info['number']=isset($_POST['number'])?intval($_POST['number']):0;
		$info['addtime'] = $_SERVER['REQUEST_TIME'];
		$data=array('error'=>1,'content'=>'');
		if($_POST['name']=='')
		{
			$data['error']=1;
			$data['content']=Lang('礼品名不能为空');
			$this->showMsg($data);
		}
		$result=Model('sign')->update($info,array('table'=>'sign_persent','id'=>$id));
		if($result)
		{
			$data['error']=0;
			$data['content']=Lang('SUCCESS_EDIT');
		
		}
		else
		{
			$data['content']=Lang('INVALID_OPERATION');
		}
		$this->showMsg($data);
	}
	public function delPersent(){
		$id=isset($_REQUEST['id'])?$_REQUEST['id']:'';
		if(is_array($id))
		{
			foreach($id as $k=>$v)
			{
				$result=Model('sign')->del_persent($v);
			}
		}
		else
		{
			$result=Model('sign')->del_persent($id);
		}
		print_r(json_encode($result));
	}
	public function persentRecord(){
		$page=isset($_REQUEST['page'])?intval($_REQUEST['page']):1;
		$record_list=Model('sign')->persent_record_list($page);
		$this->assign('persent_list',$record_list['data']);
		$this->assign('user_list_page',$record_list['pagelink']);
		$this->assign('count',$record_list['count']);
		$this->display('persent_record.html');
	}
	
}